************************************************
**ANES Cumulative File Replication for Table 2**
************************************************

recode VCF0349 (0 8 9 =.)(2=0 "No")(1=1 "Yes"), gen (proud) 
recode VCF0348 (0 8 9 =.)(2=0 "No")(1=1 "Yes"), gen (hopeful) 
recode VCF0347 (0 8 9 =.)(2=0 "No")(1=1 "Yes"), gen (afraid) 
recode VCF0346 (0 8 9 =.)(2=0 "No")(1=1 "Yes"), gen (angry) 

rename VCF0004 year
rename VCF0011z weight
rename VCF0901a state

recode VCF0301 (0=.)(1/3=0 "Democrat")(4=1 "Independent")(5/7=2 "Republican"), gen (gop3)

gen pres_gop=0
replace pres_gop=1 if year==1982 | year==1984 | year==1986 | year==1988 | year==1992 | year==2004 | year== 2008

gen copartisan=.
replace copartisan=0 if gop3==0 & pres_gop==1 | gop3==2 & pres_gop==0
replace copartisan=1 if gop3==0 & pres_gop==0 | gop3==2 & pres_gop==1


recode VCF0104 (0 3=.)(1=0)(2=1), gen(female)
recode VCF0101 (00=.), gen(age)
recode VCF0140a (8 9=.), gen(educ)
recode VCF0310 (0 9=.), gen(interest)

gen republican = VCF0301 if VCF0301>0 & VCF0301<8
recode republican (4=0)(3 5=1)(2 6=2)(1 7=3), gen(spid)

logit proud copartisan gop3 female educ interest age spid i.year [pweight=weight]
eststo proud_m

logit hopeful copartisan gop3 female educ interest age spid i.year [pweight=weight]
eststo hopeful_m

logit afraid copartisan gop3 female educ interest age spid i.year [pweight=weight]
eststo afraid_m

logit angry copartisan gop3 female educ interest age spid i.year [pweight=weight]
eststo angry_m


coefplot afraid_m angry_m proud_m hopeful_m, xline(0) drop(_cons i.year)

************************************************
**ANES 2020-2024 Panel Replication for Table 3**
************************************************

recode V201231x-V241122 (-9/-1=.)

recode V201231x (1=3 "str") (2=2 "wk") (3=1 "lean") (4=0 "ind") (5=1) (6=2) (7=3), gen(partisan_str_20)
recode V241227x (1=3 "str") (2=2 "wk") (3=1 "lean") (4=0 "ind") (5=1) (6=2) (7=3), gen(partisan_str_24)

recode V201600 (2=1) (1=0), gen(female_20)
recode V241550 (2=1) (1=0), gen(female_24)

recode V201231x  (5/7=1) (1/4=0), gen(rep_20)
recode V241227x  (5/7=1) (1/4=0), gen(rep_24)

gen ang_delta = V241121 - V201118
gen wor_delta = V241123 - V201120
gen hap_delta = V241122 - V201119
gen hop_delta = V241118 - V201115
gen prd_delta = V241124 - V201121

mean (ang_delta-prd_delta)

svyset [pweight=V240108a], psu(V240108c) strata(V240108d)

svy: reg ang_delta rep_20 female_20  V201006 V201507x V201511x partisan_str_20
est store anger
svy: reg hop_delta rep_20 female_20  V201006 V201507x V201511x partisan_str_20
est store hope
svy: reg prd_delta rep_20 female_20  V201006 V201507x V201511x partisan_str_20
est store pride

esttab anger hope pride, se label star(* 0.05 ** 0.01 *** 0.001)
esttab anger hope pride using regression_table.html, ///
	b(%9.3f) se(%9.3f) ///
    se label star(* 0.05 ** 0.01 *** 0.001) ///
    stats(r2) replace
